package com.ourclass.json;

import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

public class ObjFormate implements JsonDeserializer<Date> {

	@Override
	public Date deserialize(JsonElement element, Type arg1,
			JsonDeserializationContext arg2) throws JsonParseException {
		
		String date = element.getAsString();

		// "M/d/yy hh:mm a" // mes/dia/ano hora:min 
		SimpleDateFormat formatter = new SimpleDateFormat("M/d/yy hh:mm a");
		
		try {
				return formatter.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
	}

}
